import { Controller, Inject, Get, Query, Body, Post, Put, Param, Del } from '@midwayjs/core';
import { DictTypeService } from "@service/system/dictType.service";
import { ListDictTypeDTO, CreateDictTypeDTO, UpdateDictTypeDTO } from "@dto/system/dictType.dto";
import { Auth } from "@decorator/auth.decorator";
import { BusinessType, Log } from "@decorator/log.decorator";

@Controller('/system/dict/type')
export class PostController {
  @Inject()
  dictTypeService: DictTypeService;

  // 获取列表
  @Auth('system:dict:list')
  @Get('/list')
  async list(@Query() queryParams: ListDictTypeDTO) {
    return await this.dictTypeService.list(queryParams);
  }

  // 新增
  @Auth('system:dict:add')
  @Log({ title: '字典管理', businessType: BusinessType.ADD })
  @Post('/')
  async create(@Body() dictType: CreateDictTypeDTO) {
    return await this.dictTypeService.create(dictType);
  }

  // 删除
  @Auth('system:dict:remove')
  @Log({ title: '字典管理', businessType: BusinessType.REMOVE })
  @Del('/:dictId')
  async delete(@Param('dictId') dictId: string) {
    return await this.dictTypeService.delete(dictId);
  }

  // 修改
  @Auth('system:dict:edit')
  @Log({ title: '字典管理', businessType: BusinessType.EDIT })
  @Put('/')
  async update(@Body() dictType: UpdateDictTypeDTO) {
    return await this.dictTypeService.update(dictType);
  }

  // 获取详情
  @Auth('system:dict:query')
  @Get('/:dictId')
  async get(@Param('dictId') dictId: number) {
    return await this.dictTypeService.detail(dictId);
  }

  // 导出
  @Auth('system:dict:export')
  @Log({ title: '字典管理', businessType: BusinessType.EXPORT })
  @Post('/export')
  async export(@Body() queryParams: ListDictTypeDTO) {
    return await this.dictTypeService.export(queryParams);
  }

  // 字典选择框列表
  @Get('/optionselect')
  async optionSelect() {
    return this.dictTypeService.optionSelect();
  }

  // 刷新缓存
  @Del('/refreshCache')
  async refreshCache() {
    return await this.dictTypeService.refreshCache();
  }
}
